package cn.liyunqi.ttv.main.controller;

import cn.liyunqi.ttv.main.util.StringUtil;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import org.apdplat.word.segmentation.Segmentation;
import org.apdplat.word.segmentation.Word;

import java.net.URL;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.ResourceBundle;

public class FindImgSegmentationController  extends BaseFXController {

    @FXML
    private ScrollPane textPane;
    @FXML
    private CheckBox txtGlobalChk;
    @FXML
    private Button cleanChooseBtn;
    @FXML
    private Button combineBtn;
    @FXML
    private Button splitBtn;
    @FXML
    private Button segmentationBtn;
    @FXML
    private ScrollPane segmentationPane;
    @FXML
    private TextField basicsCoefficientTxt;
    @FXML
    private TextField globalTxt;
    @FXML
    private TextField fileNameTxt;
    @FXML
    private TextField addSegmentationTxt;
    @FXML
    private Button basicsCoefficientBtn;
    @FXML
    private Button globalBtn;
    @FXML
    private Button addSegmentationBtn;
    @FXML
    private Button previewBtn;
    @FXML
    private Button finishBtn;

    private MainUIController mainUIController;
    //分词list
    private static List<Segmentation> segmentationMap;

    //选择的文本分词

    public void setMainUIController(MainUIController mainUIController) {
        this.mainUIController = mainUIController;
        this.initAfterSetMainUI();
    }

    @Override
    public void initialize(URL location, ResourceBundle resources) {


    }

    public void initAfterSetMainUI(){
        //700
        List<List<Word>> subList = mainUIController.getSegmentationList();

        VBox vbox = new VBox();
        HBox hbox = new HBox();
        hbox.setMinHeight(30);
        double hboxWidth = 0.0;
        double sizeWidth = 11.0;

        for (int i = 0; i < subList.size(); i++) {
            List<Word> wordList = subList.get(i);
            for (int i1 = 0; i1 < wordList.size(); i1++) {
                Word word = wordList.get(i1);

                if(!StringUtil.isNullOrEmpty(word.getText())){
                    Button button = getButtonByWord(word);
                    double btnWidth = sizeWidth * 1.5 + sizeWidth * word.getText().length();
                    hboxWidth = hboxWidth + btnWidth;
                    if(hboxWidth <= 700){
                        hbox.getChildren().add(button);
                    }else{
                        vbox.getChildren().add(hbox);

                        hbox = new HBox();
                        hbox.setMinHeight(30);
                        hboxWidth = btnWidth;
                        hbox.getChildren().add(button);
                    }
                }
            }
            HBox subBox = new HBox();
            subBox.setMinHeight(10);
            vbox.getChildren().add(subBox);
        }

        textPane.setContent(vbox);
    }

    private Button getButtonByWord(Word word){
        Button button = new Button();

        button.setText(word.getText());

        return button;
    }

    @FXML
    private void cleanChooseHandle(){

    }
    @FXML
    private void combineHandle(){

    }
    @FXML
    private void splitHandle(){

    }
    @FXML
    private void segmentationHandle(){

    }
    @FXML
    private void basicsCoefficientHandle(){

    }
    @FXML
    private void globalHandle(){

    }
    @FXML
    private void addSegmentationHandle(){

    }
    @FXML
    private void previewHandle(){

    }
    @FXML
    private void finishHandle(){

    }
}
